import socket
import tkinter as tk
from tkinter import simpledialog

def send_attack(ip, port, payload):
    # Create a TCP socket
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    
    try:
        # Connect to the target IP and port
        sock.connect((ip, port))
        
        # Send the malicious payload
        sock.send(payload)
        
        print(f"Sent malicious payload to {ip}:{port}")
    except Exception as e:
        print(f"Error: {e}")
    finally:
        sock.close()

# Function to get input from user via dialog boxes
def get_input():
    root = tk.Tk()
    root.withdraw()  # Hide the main window

    # Get target IP
    target_ip = simpledialog.askstring("Input", "Enter Target IP:")
    if target_ip is None:
        return None, None, None  # If canceled
    target_port = simpledialog.askinteger("Input", "Enter Target Port:")
    if target_port is None:
        return None, None, None  # If canceled
    custom_payload = simpledialog.askstring("Input", "Enter Custom Payload:")
    if custom_payload is None:
        return None, None, None  # If canceled

    return target_ip, target_port, custom_payload.encode()

# Get input from the user
target_ip, target_port, custom_payload = get_input()

# If user provided input, proceed with the attack
if target_ip is not None and target_port is not None and custom_payload is not None:
    send_attack(target_ip, target_port, custom_payload)